package net.mcreator.servercmd.procedure;

import net.minecraftforge.common.DimensionManager;

import net.minecraft.world.WorldServer;
import net.minecraft.world.World;
import net.minecraft.world.Teleporter;
import net.minecraft.util.text.TextComponentTranslation;
import net.minecraft.util.text.TextComponentString;
import net.minecraft.util.math.Vec3d;
import net.minecraft.util.math.BlockPos;
import net.minecraft.server.MinecraftServer;
import net.minecraft.scoreboard.Scoreboard;
import net.minecraft.scoreboard.ScoreObjective;
import net.minecraft.scoreboard.ScoreCriteria;
import net.minecraft.scoreboard.Score;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.Entity;
import net.minecraft.command.ICommandSender;

import net.mcreator.servercmd.ElementsServerCmdMod;

import java.util.Map;

@ElementsServerCmdMod.ModElement.Tag
public class ProcedureHomeCmd extends ElementsServerCmdMod.ModElement {
	public ProcedureHomeCmd(ElementsServerCmdMod instance) {
		super(instance, 7);
	}

	public static void executeProcedure(Map<String, Object> dependencies) {
		if (dependencies.get("entity") == null) {
			System.err.println("Failed to load dependency entity for procedure HomeCmd!");
			return;
		}
		Entity entity = (Entity) dependencies.get("entity");
		if (((new Object() {
			public int getScore(String score) {
				if (entity instanceof EntityPlayer) {
					Scoreboard _sc = ((EntityPlayer) entity).getWorldScoreboard();
					ScoreObjective _so = _sc.getObjective(score);
					if (_so != null) {
						Score _scr = _sc.getOrCreateScore(((EntityPlayer) entity).getGameProfile().getName(), _so);
						return _scr.getScorePoints();
					}
				}
				return 0;
			}
		}.getScore("HomeWorld")) != new Object() {
			int convert(String s) {
				try {
					return Integer.parseInt(s.trim());
				} catch (Exception e) {
				}
				return 0;
			}
		}.convert(("" + ((entity.dimension)))))) {
			if (((new Object() {
				public int getScore(String score) {
					if (entity instanceof EntityPlayer) {
						Scoreboard _sc = ((EntityPlayer) entity).getWorldScoreboard();
						ScoreObjective _so = _sc.getObjective(score);
						if (_so != null) {
							Score _scr = _sc.getOrCreateScore(((EntityPlayer) entity).getGameProfile().getName(), _so);
							return _scr.getScorePoints();
						}
					}
					return 0;
				}
			}.getScore("HomeWorld")) == 0)) {
				{
					Entity _ent = entity;
					if (!_ent.world.isRemote && !_ent.isRiding() && !_ent.isBeingRidden() && _ent instanceof EntityPlayerMP) {
						int dimensionID = 0;
						class TeleporterDirect extends Teleporter {
							public TeleporterDirect(WorldServer worldserver) {
								super(worldserver);
							}

							@Override
							public void placeInPortal(Entity entity, float yawrotation) {
							}

							@Override
							public boolean placeInExistingPortal(Entity entity, float yawrotation) {
								return true;
							}

							@Override
							public boolean makePortal(Entity entity) {
								return true;
							}
						}
						EntityPlayerMP _player = (EntityPlayerMP) _ent;
						_player.mcServer.getPlayerList().transferPlayerToDimension(_player, dimensionID,
								new TeleporterDirect(_player.getServerWorld()));
						_player.connection.setPlayerLocation(DimensionManager.getWorld(dimensionID).getSpawnPoint().getX(),
								DimensionManager.getWorld(dimensionID).getSpawnPoint().getY() + 1,
								DimensionManager.getWorld(dimensionID).getSpawnPoint().getZ(), _player.rotationYaw, _player.rotationPitch);
					}
				}
			} else if (((new Object() {
				public int getScore(String score) {
					if (entity instanceof EntityPlayer) {
						Scoreboard _sc = ((EntityPlayer) entity).getWorldScoreboard();
						ScoreObjective _so = _sc.getObjective(score);
						if (_so != null) {
							Score _scr = _sc.getOrCreateScore(((EntityPlayer) entity).getGameProfile().getName(), _so);
							return _scr.getScorePoints();
						}
					}
					return 0;
				}
			}.getScore("HomeWorld")) == (-1))) {
				{
					Entity _ent = entity;
					if (!_ent.world.isRemote && !_ent.isRiding() && !_ent.isBeingRidden() && _ent instanceof EntityPlayerMP) {
						int dimensionID = -1;
						class TeleporterDirect extends Teleporter {
							public TeleporterDirect(WorldServer worldserver) {
								super(worldserver);
							}

							@Override
							public void placeInPortal(Entity entity, float yawrotation) {
							}

							@Override
							public boolean placeInExistingPortal(Entity entity, float yawrotation) {
								return true;
							}

							@Override
							public boolean makePortal(Entity entity) {
								return true;
							}
						}
						EntityPlayerMP _player = (EntityPlayerMP) _ent;
						_player.mcServer.getPlayerList().transferPlayerToDimension(_player, dimensionID,
								new TeleporterDirect(_player.getServerWorld()));
						_player.connection.setPlayerLocation(DimensionManager.getWorld(dimensionID).getSpawnPoint().getX(),
								DimensionManager.getWorld(dimensionID).getSpawnPoint().getY() + 1,
								DimensionManager.getWorld(dimensionID).getSpawnPoint().getZ(), _player.rotationYaw, _player.rotationPitch);
					}
				}
			} else if (((new Object() {
				public int getScore(String score) {
					if (entity instanceof EntityPlayer) {
						Scoreboard _sc = ((EntityPlayer) entity).getWorldScoreboard();
						ScoreObjective _so = _sc.getObjective(score);
						if (_so != null) {
							Score _scr = _sc.getOrCreateScore(((EntityPlayer) entity).getGameProfile().getName(), _so);
							return _scr.getScorePoints();
						}
					}
					return 0;
				}
			}.getScore("HomeWorld")) == 1)) {
				{
					Entity _ent = entity;
					if (!_ent.world.isRemote && !_ent.isRiding() && !_ent.isBeingRidden() && _ent instanceof EntityPlayerMP) {
						int dimensionID = 1;
						class TeleporterDirect extends Teleporter {
							public TeleporterDirect(WorldServer worldserver) {
								super(worldserver);
							}

							@Override
							public void placeInPortal(Entity entity, float yawrotation) {
							}

							@Override
							public boolean placeInExistingPortal(Entity entity, float yawrotation) {
								return true;
							}

							@Override
							public boolean makePortal(Entity entity) {
								return true;
							}
						}
						EntityPlayerMP _player = (EntityPlayerMP) _ent;
						_player.mcServer.getPlayerList().transferPlayerToDimension(_player, dimensionID,
								new TeleporterDirect(_player.getServerWorld()));
						_player.connection.setPlayerLocation(DimensionManager.getWorld(dimensionID).getSpawnPoint().getX(),
								DimensionManager.getWorld(dimensionID).getSpawnPoint().getY() + 1,
								DimensionManager.getWorld(dimensionID).getSpawnPoint().getZ(), _player.rotationYaw, _player.rotationPitch);
					}
				}
			}
		}
		if (entity instanceof EntityPlayer) {
			Scoreboard _sc = ((EntityPlayer) entity).getWorldScoreboard();
			ScoreObjective _so = _sc.getObjective("BackX");
			if (_so == null) {
				_so = _sc.addScoreObjective("BackX", ScoreCriteria.DUMMY);
			}
			Score _scr = _sc.getOrCreateScore(((EntityPlayer) entity).getGameProfile().getName(), _so);
			_scr.setScorePoints((int) (entity.posX));
		}
		if (entity instanceof EntityPlayer) {
			Scoreboard _sc = ((EntityPlayer) entity).getWorldScoreboard();
			ScoreObjective _so = _sc.getObjective("BackY");
			if (_so == null) {
				_so = _sc.addScoreObjective("BackY", ScoreCriteria.DUMMY);
			}
			Score _scr = _sc.getOrCreateScore(((EntityPlayer) entity).getGameProfile().getName(), _so);
			_scr.setScorePoints((int) (entity.posY));
		}
		if (entity instanceof EntityPlayer) {
			Scoreboard _sc = ((EntityPlayer) entity).getWorldScoreboard();
			ScoreObjective _so = _sc.getObjective("BackZ");
			if (_so == null) {
				_so = _sc.addScoreObjective("BackZ", ScoreCriteria.DUMMY);
			}
			Score _scr = _sc.getOrCreateScore(((EntityPlayer) entity).getGameProfile().getName(), _so);
			_scr.setScorePoints((int) (entity.posZ));
		}
		{
			Entity _ent = entity;
			if (!_ent.world.isRemote && _ent.world.getMinecraftServer() != null) {
				_ent.world.getMinecraftServer().getCommandManager().executeCommand(new ICommandSender() {
					@Override
					public String getName() {
						return "";
					}

					@Override
					public boolean canUseCommand(int permission, String command) {
						return true;
					}

					@Override
					public World getEntityWorld() {
						return _ent.world;
					}

					@Override
					public MinecraftServer getServer() {
						return _ent.world.getMinecraftServer();
					}

					@Override
					public boolean sendCommandFeedback() {
						return false;
					}

					@Override
					public BlockPos getPosition() {
						return _ent.getPosition();
					}

					@Override
					public Vec3d getPositionVector() {
						return new Vec3d(_ent.posX, _ent.posY, _ent.posZ);
					}

					@Override
					public Entity getCommandSenderEntity() {
						return _ent;
					}
				}, (("tp @s ") + "" + ((new Object() {
					public int getScore(String score) {
						if (entity instanceof EntityPlayer) {
							Scoreboard _sc = ((EntityPlayer) entity).getWorldScoreboard();
							ScoreObjective _so = _sc.getObjective(score);
							if (_so != null) {
								Score _scr = _sc.getOrCreateScore(((EntityPlayer) entity).getGameProfile().getName(), _so);
								return _scr.getScorePoints();
							}
						}
						return 0;
					}
				}.getScore("HomeX"))) + "" + (" ") + "" + ((new Object() {
					public int getScore(String score) {
						if (entity instanceof EntityPlayer) {
							Scoreboard _sc = ((EntityPlayer) entity).getWorldScoreboard();
							ScoreObjective _so = _sc.getObjective(score);
							if (_so != null) {
								Score _scr = _sc.getOrCreateScore(((EntityPlayer) entity).getGameProfile().getName(), _so);
								return _scr.getScorePoints();
							}
						}
						return 0;
					}
				}.getScore("HomeY"))) + "" + (" ") + "" + ((new Object() {
					public int getScore(String score) {
						if (entity instanceof EntityPlayer) {
							Scoreboard _sc = ((EntityPlayer) entity).getWorldScoreboard();
							ScoreObjective _so = _sc.getObjective(score);
							if (_so != null) {
								Score _scr = _sc.getOrCreateScore(((EntityPlayer) entity).getGameProfile().getName(), _so);
								return _scr.getScorePoints();
							}
						}
						return 0;
					}
				}.getScore("HomeZ")))));
			}
		}
		if (entity instanceof EntityPlayer && !entity.world.isRemote) {
			((EntityPlayer) entity)
					.sendStatusMessage(new TextComponentString((new TextComponentTranslation("msg.home").getUnformattedComponentText())), (false));
		}
	}
}
